package xyz.robinbingo.turing.dubbo.common.serialize;

import com.alibaba.fastjson.JSON;

import java.io.IOException;
import java.io.InputStream;

/**
 * Serializer
 *
 * @author Robin
 * @date 2021/1/29 下午2:42
 **/
public class Serializer {

    public static byte[] serialize(Object o) {
        return JSON.toJSONBytes(o);
    }

    public static <T> T deserialize(InputStream in, Class<T> clazz) {
        try {
            return (T) JSON.parseObject(in, clazz);
        } catch (IOException e) {
            e.printStackTrace();
        }
        throw new RuntimeException("deserialize error");
    }
}
